﻿using StarPizza.Model.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StarPizza.Model.Ordering
{
    class OrderProcessor
    {
        OrderHistory orderHistory;
        CashRegister cashRegister;
        IStorageManipulator storageManipulator;

        public OrderProcessor(OrderHistory orderHistory, CashRegister cashRegister, IStorageManipulator storageManipulator)
        {
            this.orderHistory = orderHistory;
            this.cashRegister = cashRegister;
            this.storageManipulator = storageManipulator;
        }
        public void AddPizza(IPizza pizza)
        {
            storageManipulator.ReserveIngredients(pizza);
        }
        public void CancelPizza(IPizza pizza)
        {
            storageManipulator.FreeUpIngredients(pizza);
        }
        public void FinalizeOrder(IEnumerable<IPizza> pizzas)
        {
            orderHistory.SaveOrderInfo(pizzas);
            cashRegister.Cash += pizzas.Sum(pizza => pizza.Price);
            storageManipulator.PerformAmountChange();
        }
    }
}
